<?php
/****
 * log_base
 * 功能描述 : 游戏日志
 * 作	者  : qingkuangs(qingkuangs@gmail.com)
 * 日   期  : 2011-05-16
 *
****/
class log_base {
	protected static $fp = null;
	function __construct($player_id = "") {
		if(self::$fp == null || !is_resource(self::$fp)) {

			$path = SQL_LOG_PATH."data/";
			if(!is_dir($path)) {
				$shell = "mkdir -p ".$path;

				shell_exec($shell);
			}
			$minute = date("i");

			$log_m = sprintf("%s0",floor($minute / 10));

			$log_file = $path . "/".date("YmdH").$log_m."_".substr(md5($player_id), 0, 1).".sql";
			self::$fp = fopen($log_file,"a");
		}
    }
/**
 * 日志
 *
 * @return void
**/
	public function log_write($content) {
		if(self::$fp != null && is_resource(self::$fp)) {
			fwrite(self::$fp,$content);
		}
	}

/**
 * 生成SQL
 * table 表名
 * arr 数组 key==field value==value
 * @return void
**/
/*public function make_sql($table, $arr){
		if(empty($arr)||empty($table)){
			return false;
		}
		$sql 	= 'INSERT INTO log_'.$table.' SET ';
		$spilit = null;
		foreach ($arr as $field=>$value){
			$sql 	.= $spilit.'`'.$field.'` = "'.$value.'"';
			$spilit  = ', ';
		}

		$this->log_write($sql.";\n");
}*/

	function __destruct() {
		if(self::$fp) {
			@fclose(self::$fp);
			self::$fp = null;
		}
    }
}

?>